<template>
  <div class="help-tpl-item">
    <Spin :spinning="spinning">
      <div class="help-tpl-top flex">
        <div class="help-tpl-card"></div>
        <div class="help-tpl-header">
          <p class="hld-title">{{ noviceItem.itemName }}</p>
          <p class="hld-tag">快速了解{{ cutText(noviceItem.itemName) }}</p>
        </div>
      </div>
      <div class="help-tpl-text">
        <p v-for="(item, index) in novice" :key="index" :title="item.article_title">
          <a :href="'/articleDetail/' + item.article_id" target="_blank">{{ item.article_title }}</a>
        </p>
      </div>
    </Spin>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, toRefs, onMounted } from "vue";
import { Spin } from "ant-design-vue";
import { getArticleListApi } from "/@/api/article";
export default defineComponent({
  name: "helpTplItem",
  components: { Spin },
  props: {
    noviceItem: {
      type: Object,
      default: {},
    },
  },
  setup(props) {
    const { noviceItem } = toRefs(props);
    const novice = ref([]);
    const spinning = ref<boolean>(false);

    const getArticleList = async () => {
      spinning.value = true;
      let data = await getArticleListApi({
        //小程序
        itemId: noviceItem.value.itemId,
        current: 1,
        size: 4,
      });
      novice.value = data.records;
      spinning.value = false;
    };

    onMounted(getArticleList);

    return {
      novice,
      noviceItem,
      spinning,
    };
  },
  methods: {
    cutText: function (val) {
      if (val) {
        return val.slice(0, -2);
      }
    },
  },
});
</script>

<style lang="less" scoped>
.help-tpl-item {
  width: 282px;
  height: 270px;
  padding: 24px;
  border: 1px solid #e0e5eb;
  border-radius: 2px;

  .help-tpl-top {
    padding-bottom: 24px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e0e5eb;
  }

  .help-tpl-card {
    width: 60px;
    min-width: 60px;
    height: 60px;
    border-radius: 4px;
    background: #f00;
  }

  &:first-child {
    .help-tpl-card {
      background: url("/@/assets/img/help-tpl1.png") no-repeat center;
    }
  }

  &:nth-child(2) {
    .help-tpl-card {
      background: url("/@/assets/img/help-tpl2.png") no-repeat center;
    }
  }

  &:nth-child(3) {
    .help-tpl-card {
      background: url("/@/assets/img/help-tpl3.png") no-repeat center;
    }
  }

  &:nth-child(4) {
    .help-tpl-card {
      background: url("/@/assets/img/help-tpl4.png") no-repeat center;
    }
  }

  .help-tpl-header {
    padding: 8px 16px 0;

    .hld-title {
      margin: 0 0 5px;
      font-size: 16px;
      font-weight: 600;
      line-height: 22px;
      color: #000000;
    }

    .hld-tag {
      margin: 0;
      font-size: 14px;
      line-height: 20px;
      color: #666666;
    }
  }

  .help-tpl-text {
    p {
      padding-left: 10px;
      margin: 12px 0 0;
      line-height: 20px;
      position: relative;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      cursor: pointer;

      &:hover {
        color: #0078ff;
      }

      &:after {
        content: "";
        position: absolute;
        left: 0;
        top: 8px;
        width: 4px;
        height: 4px;
        background: #0078ff;
        border-radius: 50%;
      }
    }
  }
}
</style>
